package com.playball.lottery.frm.set;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;

import com.githang.statusbar.StatusBarCompat;
import com.playball.lottery.R;
import com.playball.lottery.base.BaseActivity;
import com.playball.lottery.customview.ShowTipDialog;
import com.playball.lottery.util.DefConstants;
import com.playball.lottery.util.MyPreference;
import com.playball.lottery.util.SysApplication;


/**
 * 开奖通知设置页面
 * 
 * @author Administrator
 * 
 */
public class SetKJNoticeActivity extends BaseActivity implements DefConstants {

	// String userName;
	// String userPwd;
	// private boolean bJump2YHZX = false;

	private ShowTipDialog showdialog = new ShowTipDialog();
	/** 运行上下文 */
	private Context context;
	// /** 进球声音提示 */
	// private CheckBox cb1;
	// /** 红黄牌声音提示 */
	// private CheckBox cb2;

	private CheckBox cb_ssq;
	private CheckBox cb_dlt;
	private CheckBox cb_fc3d;
	private CheckBox cb_pl3;
	private CheckBox cb_qxc;
	private CheckBox cb_qlc;
	private CheckBox cb_pl5;
	private CheckBox cb_sfc;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.context = this;
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.set_kjnotice);
		StatusBarCompat.setStatusBarColor(this,Color.RED, true);
		SysApplication.getInstance().addActivity(this);

		// 标题
		TitleBar();

		// 声音提示
		// cb1 = (CheckBox) findViewById(R.id.set_cb_hint1);
		// cb2 = (CheckBox) findViewById(R.id.set_cb_hint2);
		cb_ssq = (CheckBox) findViewById(R.id.set_cb_ssq);
		cb_dlt = (CheckBox) findViewById(R.id.set_cb_dlt);
		cb_fc3d = (CheckBox) findViewById(R.id.set_cb_fc3d);
		cb_pl3 = (CheckBox) findViewById(R.id.set_cb_pl3);
		cb_qxc = (CheckBox) findViewById(R.id.set_cb_qxc);
		cb_qlc = (CheckBox) findViewById(R.id.set_cb_qlc);
		cb_pl5 = (CheckBox) findViewById(R.id.set_cb_pl5);
		cb_sfc = (CheckBox) findViewById(R.id.set_cb_sfc);

		// // 进球声音提示
		// // 根据存贮的设置决定checkbox的选中状态
		// if (MyPreference.getInstance(context).getSoundFlgJQ()) {
		// // 默认为选中
		// cb1.setChecked(true);
		// } else {
		// cb1.setChecked(false);
		// }

		// cb1.setOnCheckedChangeListener(new
		// CompoundButton.OnCheckedChangeListener() {
		// public void onCheckedChanged(CompoundButton buttonView, boolean
		// isChecked) {
		// if (isChecked) {
		// // 存贮数据 "选中");
		// MyPreference.getInstance(context).storeSoundFlgJQ(true);
		// } else {
		// MyPreference.getInstance(context).storeSoundFlgJQ(false);
		// }
		// }
		// });

		// // 红黄牌声音提示
		// if (MyPreference.getInstance(context).getSoundFlgHH()) {
		// // 默认为选中
		// cb2.setChecked(true);
		// } else {
		// cb2.setChecked(false);
		// }
		// cb2.setOnCheckedChangeListener(new
		// CompoundButton.OnCheckedChangeListener() {
		// public void onCheckedChanged(CompoundButton buttonView, boolean
		// isChecked) {
		// if (isChecked) {
		// // 存贮数据 "选中");
		// MyPreference.getInstance(context).storeSoundFlgHH(true);
		// } else {
		// MyPreference.getInstance(context).storeSoundFlgHH(false);
		// }
		// }
		// });

		if (MyPreference.getInstance(context).isSSQNotice()) {
			cb_ssq.setChecked(true);
		} else {
			cb_ssq.setChecked(false);
		}
		cb_ssq.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				MyPreference.getInstance(context).setSSQNotice(arg1);
			}
		});

		if (MyPreference.getInstance(context).isDLTNotice()) {
			cb_dlt.setChecked(true);
		} else {
			cb_dlt.setChecked(false);
		}
		cb_dlt.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				MyPreference.getInstance(context).setDLTNotice(arg1);
			}
		});

		if (MyPreference.getInstance(context).isFC3DNotice()) {
			cb_fc3d.setChecked(true);
		} else {
			cb_fc3d.setChecked(false);
		}
		cb_fc3d.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				MyPreference.getInstance(context).setFC3DNotice(arg1);
			}
		});

		if (MyPreference.getInstance(context).isPL3Notice()) {
			cb_pl3.setChecked(true);
		} else {
			cb_pl3.setChecked(false);
		}
		cb_pl3.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				MyPreference.getInstance(context).setPL3Notice(arg1);
			}
		});

		if (MyPreference.getInstance(context).isQXCNotice()) {
			cb_qxc.setChecked(true);
		} else {
			cb_qxc.setChecked(false);
		}
		cb_qxc.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				MyPreference.getInstance(context).setQXCNotice(arg1);
			}
		});

		if (MyPreference.getInstance(context).isQLCNotice()) {
			cb_qlc.setChecked(true);
		} else {
			cb_qlc.setChecked(false);
		}
		cb_qlc.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				MyPreference.getInstance(context).setQLCNotice(arg1);
			}
		});

		if (MyPreference.getInstance(context).isPL5Notice()) {
			cb_pl5.setChecked(true);
		} else {
			cb_pl5.setChecked(false);
		}
		cb_pl5.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				MyPreference.getInstance(context).setPL5Notice(arg1);
			}
		});

		if (MyPreference.getInstance(context).isSFCNotice()) {
			cb_sfc.setChecked(true);
		} else {
			cb_sfc.setChecked(false);
		}
		cb_sfc.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				MyPreference.getInstance(context).setSFCNotice(arg1);
			}
		});

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onResume()
	 */
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		
		// processLoginOrLonout();
	}

	public void onPause() {
		super.onPause();
		
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			// Intent intent = new Intent(context, JddMainFrameActivity.class);
			// context.startActivity(intent);
			finish();// 销毁对象
		}
		return true;
	};

	// TitleBar标题栏
	public void TitleBar() {
		// Title信息(返回+Title)
		Button back = (Button) findViewById(R.id.top_title_back);
		back.getBackground().setAlpha(255);// 不需要返回加上这句话，透明度0~255透明度值 ，值越小越透明
		back.setVisibility(View.VISIBLE);
		back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				// Intent intent = new Intent(context,
				// JddMainFrameActivity.class);
				// context.startActivity(intent);
				finish();// 销毁对象
			}
		});

		TextView info = (TextView) findViewById(R.id.top_title_info);
		info.setText(R.string.setkjnotice);// R.string.set

		Button refres = (Button) findViewById(R.id.top_title_refres);
		// refres.getBackground().setAlpha(0);// 不需要刷新加上这句话，透明度0~255透明度值 ，值越小越透明
		refres.setVisibility(View.INVISIBLE);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onActivityResult(int, int,
	 * android.content.Intent)
	 */
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		if (requestCode == REQ_CODE_SETMAIN) {
			if (resultCode == RESULT_OK) {
				// processLoginOrLonout();
				// MainActivity.setYHZX();
			}
		} else if (requestCode == REQ_CODE_SETMAIN_2_REG) {
			if (resultCode == RESULT_OK) {
				// bJump2YHZX = true;
				// userName = data.getStringExtra("userName");
				// userPwd = data.getStringExtra("userPwd");
				// AsyncLoader task = new AsyncLoader();
				// task.execute("101");
			}
		}

	}

	// public boolean CheckUserLogin() {
	// // app = (ApplicationBall) getApplication();
	// if (!ApplicationData.getInstance().getLoginName().equals("") &&
	// !ApplicationData.getInstance().getLoginPwd().equals("") ||
	// !ApplicationData.getInstance().getUserID().equals("")) {
	// return true;
	// } else {
	// return false;
	// }
	// }

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		super.finish();
		SysApplication.getInstance().removeActivity(this);
	};

	// public class AsyncLoader extends AsyncTask<String, Integer, String> {//
	// 继承AsyncTask
	//
	// // 1.准备运行
	// protected void onPreExecute() {
	// showdialog.showDialog(SetKJNoticeActivity.this);
	// }
	//
	// // 2.正在后台运行
	// @Override
	// protected String doInBackground(String... params) {
	// String strResult;
	// try {
	// // 设置请求所需参数
	// JSONObject param = new JSONObject();
	// param.put("Name", userName);
	// param.put("Pw", userPwd);// Password
	// String action = params[0];
	// // 获取请求返回值
	// strResult = GetRequestParams.getRequestResult(param.toString(), action,
	// getApplicationContext());
	// return strResult;
	// } catch (Exception e) {
	// // TODO: handle exception
	// Log.e("error", e.toString());
	// return null;
	// }
	// }
	//
	// // 3.进度更新
	// protected void onProgressUpdate(Integer... progress) {
	// }
	//
	// // 4.完成后台任务
	// protected void onPostExecute(String result) {
	// if (result != null) {
	// try {
	// JSONTokener jsonParser = new JSONTokener(result);
	// JSONObject js = (JSONObject) jsonParser.nextValue();
	// // 接下来的就是JSON对象的操作了
	// if (Integer.parseInt(js.getString("Code")) == 0) {
	// // 保存用户名，密码,方便后边调用
	// // app = (ApplicationBall) getApplication();
	// ApplicationData.getInstance().setLoginName(userName);
	// ApplicationData.getInstance().setLoginPwd(userPwd);
	// // 保存登录时返回的userId进全局变量
	// ApplicationData.getInstance().setUserID(js.getString("Data"));
	// // processLoginOrLonout();
	// if (bJump2YHZX == true) {
	// // MainActivity.setYHZX();
	// bJump2YHZX = false;
	// }
	// } else {
	// Toast.makeText(SetKJNoticeActivity.this, js.getString("Data"),
	// Toast.LENGTH_SHORT).show();
	// }
	// } catch (JSONException ex) {
	// // 异常处理代码
	// Log.e("error", ex.toString());
	// } finally {
	// showdialog.closeDialog();
	// }
	// } else {
	// Toast.makeText(SetKJNoticeActivity.this, getString(R.string.problem_01),
	// Toast.LENGTH_LONG).show();
	// }
	// }
	//
	// // 5.完成后操作
	// protected void onCancelled() {
	// }
	// }
}